package cn.kuick.match2.test5;

import java.util.ArrayList;

public class TelephoneCombination {

	public static String[] MAP = new String[10];
	static {
		MAP[2] = "abc";
		MAP[3] = "def";
		MAP[4] = "ghi";
		MAP[5] = "jkl";
		MAP[6] = "mno";
		MAP[7] = "pgrs";
		MAP[8] = "tuv";
		MAP[9] = "wxyz";
	}
	
	public static void innerOutput(int i, ArrayList<String> mid, ArrayList<String> output, StringBuffer sb) {
		if (i < mid.size()) {
			String text = mid.get(i);
		
			for(int j=0; j<text.length(); j++) {
				char ch = text.charAt(j);
				
				sb.append(ch);
				
				if (i == mid.size() - 1) {
					output.add(sb.toString());
				} else {
					innerOutput(i + 1, mid, output, sb);
				}
				
				sb.setLength(sb.length() - 1);
			}
		}
	}
	
	public static ArrayList<String> allMatch(String nums) {
		ArrayList<String> output = new ArrayList<>();
		
		ArrayList<String> mid = new ArrayList<>();
		
		for(int i=0; i<nums.length(); i++) {
			char ch = nums.charAt(i);
			mid.add(MAP[Integer.parseInt(ch + "")]);
		}
		
		StringBuffer sb = new StringBuffer();
		innerOutput(0, mid, output, sb);
		
		return output ;
	}
	
	public static void main(String[] args) {
		ArrayList<String> output = allMatch("79");
		
		System.out.print("[");
		
		for(int i=0; i<output.size(); i++) {
			System.out.print("\"");
			System.out.print(output.get(i));
			
			if (i == output.size() - 1) {
				System.out.print("\"");
			} else {
				System.out.print("\",");
			}
		}
		
		System.out.println("]");
	}

}
